<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios.min.js"></script>
    <script src="../../js/dayjs.min.js"></script>
    <link rel="stylesheet" href="../../plugins/element_UI/index.css">
    <script src="../../plugins/element_UI/index.js"></script>
</head>
<body>
<style>
    .el-table .warning-row {
        background: #f9c855;
    }

    .el-table .error-row {
        background: #909399;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }

    .el-input--suffix .el-input__inner {
        padding-right: 0px;
    }

    .el-date-editor--daterange.el-input, .el-date-editor--daterange.el-input__inner, .el-date-editor--timerange.el-input, .el-date-editor--timerange.el-input__inner {
        width: 225px;
    }

    .el-input__inner {
        -webkit-appearance: none;
        background-color: #FFF;
        background-image: none;
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        color: #606266;
        display: inline-block;
        font-size: inherit;
        height: 32px;
        line-height: 40px;
        outline: 0;
        padding: 0 15px;
        -webkit-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
        transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
        width: 100%;
    }

    .el-table .cell {
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        word-break: break-all;
        line-height: 15px;
        padding-right: 10px;
    }

    #page {
        height: 40px;
        line-height: 40px;
        position: fixed;
        bottom: 34px;
        width: 100%;
        text-align: start;
        /*background: #393D49;*/
        color: #fff;
        font-family: Arial;
        font-size: 12px;
        letter-spacing: 1px;
    }

    .el-table .DisableSelection .cell .el-checkbox__inner {
        display: none;
        position: relative;
    }

    .el-table .DisableSelection .cell:before {
        content: "";
        position: absolute;
    }
</style>
<div id="app">
    <div>
        <el-form :inline="true"  class="el-search-row-d" style="margin-right: auto">
            <el-form-item>
                <template>
                    <el-radio v-model="status" label="1" @change="init">停诊</el-radio>
                    <el-radio v-model="status" label="0" @change="init">正常</el-radio>
                    <el-radio v-model="status" label="2" @change="init">全部</el-radio>
                </template>
            </el-form-item>
            <el-form-item><el-date-picker
                    id="datePicker"
                    v-model="datePickerArray"
                    size="small" type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions"
            >
            </el-date-picker></el-form-item>
            <el-form-item><el-input
                    placeholder="医生姓名模糊查询"
                    v-model="docName"
                    style="width: fit-content"
                    @change="docnameselect"
                    clearable>
            </el-input></el-form-item>
            <el-form-item><el-select v-model="hospitalId" :filterable="true" :disabled="isHidden"
                                     placeholder="请选择医院">
                <el-option
                        v-for="hospital in hospitals"
                        :key="hospital.id"
                        :label="hospital.hosName"
                        :value="hospital.id">
                </el-option>
            </el-select></el-form-item>
            <el-form-item><el-select v-model="depId" filterable placeholder="请选择科室">
                <el-option
                        v-for="department in departments"
                        :key="department.id"
                        :label="department.depName"
                        :value="department.id">
                </el-option>
            </el-select></el-form-item>
            <el-form-item><el-select v-model="doctorId" :filterable="true" placeholder="请选择医生">
                <el-option
                        v-for="doctor in doctors"
                        :key="doctor.id"
                        :label="doctor.doctorName"
                        :value="doctor.id">
                </el-option>
            </el-select></el-form-item>
            <el-form-item><el-select v-model="week" filterable placeholder="选择星期">
                <el-option
                        v-for="week in weekList"
                        :key="week.id"
                        :label="week.name"
                        :value="week.id">
                </el-option>
            </el-select></el-form-item>

            <el-form-item><el-button size="small" type="primary" @click="init">检索</el-button></el-form-item>
            <el-form-item><el-button size="small" type="success" @click="schedulingCache">缓存处理</el-button></el-form-item>
            <el-form-item><el-button size="small" type="danger" @click="stopList" :disabled="isDisabled">批量停诊</el-button></el-form-item>
            <el-form-item><el-button size="small" type="danger" @click="jktSchedulingUpload">上传(健康通)</el-button></el-form-item>
        </el-form>
        <el-dialog title="编辑" :visible.sync="dialogFormVisible" @close="closeDiglog" width="80%"
                   :close-on-click-modal="false">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                <el-form-item label="医院名称" prop="hospitalId">
                    <el-select v-model="ruleForm.hospitalId" filterable placeholder="请选择医院" :disabled="true">
                        <el-option
                                v-for="hospital in hospitals"
                                :key="hospital.id"
                                :label="hospital.hosName"
                                :value="hospital.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-row type="fix" class="right-10">
                    <el-col :span="8">
                        <el-form-item label="所属科室" prop="depId">
                            <el-select v-model="ruleForm.depId" filterable placeholder="请选择" :disabled="true">
                                <el-option
                                        v-for="department in departments"
                                        :key="department.id"
                                        :label="department.depName"
                                        :value="department.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="医生" prop="doctorName">
                            <el-input v-model="ruleForm.doctorName" type="text" :disabled="true"
                                      show-word-limit></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="挂号类型" prop="binId">
                            <el-select v-model="ruleForm.binId" filterable placeholder="请选择" :disabled="true">
                                <el-option
                                        v-for="bindInfo in bindInfos"
                                        :key="bindInfo.id"
                                        :label="bindInfo.binName"
                                        :value="bindInfo.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row type="fix" class="right">
                    <el-col :span="8">
                        <el-form-item label="星期几" prop="week">
                            <el-select v-model="ruleForm.week" placeholder="请选择" :disabled="true">
                                <el-option
                                        v-for="week in weekList"
                                        :key="week.id"
                                        :label="week.name"
                                        :value="week.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="上下午" prop="timeState">
                            <el-select v-model="ruleForm.timeState" placeholder="请选择" :disabled="true">
                                <el-option
                                        v-for="time in timeList"
                                        :key="time.id"
                                        :label="time.name"
                                        :value="time.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="平均就诊时间" prop="averageVisitTime">
                            <el-input v-model="ruleForm.averageVisitTime" type="number" :disabled="true"
                                      placeholder="平均就诊时间" maxlength="3" min="1" max="60"
                                      show-word-limit></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="号源总数" prop="amount">
                            <el-input v-model="ruleForm.amount" type="number" placeholder="请输入号源总数" maxlength="3"
                                      show-word-limit></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="预约起始号" prop="appointmentBegin">
                            <el-input v-model="ruleForm.appointmentBegin" type="number" placeholder="请输预约起始号"
                                      maxlength="3" :disabled="true"
                                      show-word-limit></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="预约号源数" prop="appointmentAmount">
                            <el-input v-model="ruleForm.appointmentAmount" type="number" placeholder="请输入号源总数"
                                      maxlength="3" :disabled="true"
                                      show-word-limit></el-input>
                        </el-form-item>
                    </el-col>

                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="费用上传" prop="registrationFee">
                            <el-radio v-model="ruleForm.registrationFee" label="0">全部上传</el-radio>
                            <el-radio v-model="ruleForm.registrationFee" label="1">挂号费上传</el-radio>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="间隔数" prop="increase">
                            <el-select v-model="ruleForm.increase" placeholder="请选择" :disabled="true">
                                <el-option label="0" value="0"></el-option>
                                <el-option label="1" value="1"></el-option>
                                <el-option label="2" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="排班日期" prop="schedulingTime" :disabled="true">
                            <el-date-picker
                                    v-model="ruleForm.schedulingTime"
                                    type="date"
                                    placeholder="选择日期" :disabled="true">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-form-item style="flex-flow: wrap;justify-items: end">
                    <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                </el-form-item>
                <el-table :data="ordSourceDetailList"
                          ref="multipleTable"
                          tooltip-effect="dark"
                          :row-class-name="tableRowClassName"
                          @select="sourceHandleSelectionChange"
                          @select-all="selectAll"
                          max-height="600">
                    <el-table-column
                            type="selection"
                            :selectable="checkboxT"
                            width="55">
                    </el-table-column>
                    <el-table-column
                            prop="serialNumber"
                            label="号源序号"
                            width="100">
                    </el-table-column>
                    <el-table-column
                            prop="visitTime"
                            label="就诊时间点"
                            width="100">
                    </el-table-column>
                    <el-table-column
                            prop="type"
                            label="类型"
                            :formatter=formatterType
                            width="100">
                    </el-table-column>

                    <el-table-column
                            prop="state"
                            label="使用状态"
                            :formatter=formatterState
                            width="100">
                    </el-table-column>
                    <el-table-column
                            prop="status"
                            label="号源状态"
                            :formatter=formatterStatus
                            width="100">
                    </el-table-column>
                </el-table>
            </el-form>
        </el-dialog>
    </div>

    <div>
        <template>
            <el-table
                    :data="tableData"
                    type="index"
                    :row-class-name="tableRowClassName"
                    :max-height="tableHeight"
                    align="center"
                    :header-cell-class-name="cellClass"
                    border
                    ref="table"
                    style="width: 100%"
                    @select="ordSchedulingHandleSelectionChange"
                    @select-all="selectOrdSchedulingAll"
                    size="mini">
                <el-table-column
                        type="selection"
                        :selectable="checkboxTB"
                        width="55">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="hospitalId"
                        label="医院"
                        align="center"
                        sortable
                        :formatter=formatterHospital
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="depName"
                        label="科室名称"
                        sortable
                        align="center"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="doctorName"
                        label="医生姓名"
                        align="center"
                        sortable
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="binName"
                        label="挂号类型"
                        align="center"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="week"
                        label="星期"
                        align="center"
                        sortable
                        :formatter="formatterWeek"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="amount"
                        label="号源总数"
                        align="center"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="timeState"
                        label="上下午"
                        :formatter="formatterTimeState"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="schedulingTime"
                        label="排班时间"
                        sortable
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="startTime"
                        label="门诊开始"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="endTime"
                        label="门诊结束"
                        width="100">
                </el-table-column>

                <el-table-column
                        prop="appointmentBegin"
                        label="开放第三方起始号源"
                        width="100">
                </el-table-column>

                <el-table-column
                        prop="appointmentAmount"
                        label="开放第三方预约数量"
                        width="120">
                </el-table-column>


                <el-table-column
                        prop="doctorPracticeScope"
                        label="放号渠道"
                        :formatter="formatterDoctorPracticeScope"
                        width="120">
                </el-table-column>


                <el-table-column
                        prop="averageVisitTime"
                        label="平均就诊时间"
                        align="center"
                        width="60">
                </el-table-column>


                <el-table-column
                        prop="stopServiceReason"
                        label="停诊原因"
                        align="center"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="originalSchedule"
                        label="原HIS排班ID"
                        align="center"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="timeStamp"
                        label="上次更新时间"
                        align="center"
                        sortable
                        width="120">
                </el-table-column>

                <el-table-column
                        fixed="right"
                        label="操作"
                        width="240">
                    <template slot-scope="scope">
                        <el-button
                                @click.native.prevent="jktSchedulingUploadSingle(scope.$index,scope.row)"
                                type="primary" :disabled="(scope.row.status==1 || scope.row.status==2)  && !type"
                                size="mini" circle>上传
                        </el-button>
                        <el-button
                                @click.native.prevent="editRow(scope.$index,scope.row)"
                                type="primary" :disabled="(scope.row.status==1 || scope.row.status==2)  && !type"
                                size="mini" circle>编辑
                        </el-button>
                        <el-button
                                @click.native.prevent="deleteRow(scope.$index,scope.row)"
                                type="danger" :disabled="scope.row.status==1 || scope.row.status==2 "
                                size="mini" circle>停诊
                        </el-button>
                        <el-button
                                @click.native.prevent="detailRow(scope.$index,scope.row)"
                                type="success" :disabled="(scope.row.status==0) "
                                size="mini" circle>删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
    </div>
    <div id="page">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentPageChange"
                :current-page="currentPage"
                :page-sizes="[15, 30, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</div>
</body>
<script>

    let app = new Vue ({
        el: '#app',
        data() {
            let checkAmount = (rule, value, callback) => {

                if (value == undefined || value == null) {
                    return callback (new Error ('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test (value)) {
                        if (parseInt (value) <= 0) {
                            return callback (new Error ('号源数不能小于1'));
                        }
                        if (parseInt (value) < this.currentAmount) {
                            console.log (value, this.currentAmount)
                            return callback (new Error ('号源数不能小于当前数'));
                        }
                    } else {
                        return callback (new Error ('请输入正确号源数'));
                    }
                    callback ();
                }
                callback ();
            };
            let checkAppointmentBegin = (rule, value, callback) => {
                if (value == undefined || value == null) {
                    return callback (new Error ('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test (value)) {
                        if (parseInt (value) > 0) {
                            callback ();
                        } else {
                            return callback (new Error ('预约起始号不能小于1'));
                        }
                        if (parseInt (value) < parseInt (this.ruleForm.amount)) {
                            callback ();
                        } else {
                            return callback (new Error ('预约起始号不能大于号源总数'));
                        }
                        if (parseInt (this.ruleForm.appointmentAmount) <= parseInt (this.ruleForm.amount) - parseInt (value) + 1) {
                            callback ();
                        } else {
                            return callback (new Error ('预约号数量不能大于号源总数减去起始号量'));
                        }
                    } else {
                        return callback (new Error ('请输入正确预约起始号'));
                    }
                }
            };
            let checkAppointmentAmount = (rule, value, callback) => {
                if (value == undefined || value == null) {
                    return callback (new Error ('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test (value)) {
                        if (parseInt (value) <= parseInt (this.ruleForm.amount) - parseInt (this.ruleForm.appointmentBegin) + 1) {
                            callback ();
                        } else {
                            return callback (new Error ('预约号数量不能大于号源总数减去起始号量'));
                        }
                    } else {
                        return callback (new Error ('请输入正确预约起始号'));
                    }
                }
            };
            let checkAverageVisitTime = (rule, value, callback) => {
                console.log (value)
                if (value == undefined || value == null) {
                    return callback (new Error ('不能为空'));
                } else {
                    const reg1 = /^[1-9]\d*|0$/
                    if (reg1.test (value)) {
                        if (parseInt (value) < 60) {
                            callback ();
                        } else {
                            return callback (new Error ('平均就诊时间不能大于60'));
                        }
                    } else {
                        return callback (new Error ('平均就诊时间不能大于60'));
                    }
                }
            };
            return {
                checkAll: false, //是否全选
                sourceTableData: [],  // 原始数据
                multipleSelection: [],
                tableData: [],
                currentPage: 1,
                pageSize: 50,
                totalPage: 1,
                total: 1000,
                scrollDistance: 0,
                tableHeight: 100,
                hospitalId: JSON.parse (localStorage.getItem ("user")).hospitalId,
                type: false,
                isDisabled: true,
                isHidden: false,
                depName: '',
                depId: null,
                doctorId: null,
                doctorName: "",
                docName: "",
                status: '0',
                week: null,
                loading: true,
                currentAmount: 0,
                currentUpRow: null,
                hospitals: [],
                departments: [],
                bindInfos: [],
                doctors: [],
                ordSourceDetailList: [],
                schedulingList: [],
                curStatus: 0,
                noStatus: 0,
                ruleForm: {
                    amount: 20,
                    amountAdd: null,
                    amountCancel: null,
                    amountCurrent: null,
                    amountReduce: null,
                    amountSurplus: null,
                    amountUse: null,
                    appointmentAmount: null,
                    appointmentBegin: null,
                    averageVisitTime: 3,
                    binId: null,
                    binName: null,
                    clinicAddress: null,
                    depId: null,
                    depName: null,
                    doctorId: null,
                    doctorName: null,
                    endTime: null,
                    hospitalId: null,
                    id: null,
                    increase: 0,
                    schedulingTime: null,
                    startTime: null,
                    state: null,
                    status: null,
                    stopServiceReason: null,
                    templateId: null,
                    timeStamp: null,
                    timeState: null,
                    week: null,
                    registrationFee: "0"
                },
                rules: {
                    amount: [
                        {required: true, validator: checkAmount, trigger: ['blur', 'change']}
                    ],
                    averageVisitTime: [
                        {required: true, validator: checkAverageVisitTime, trigger: ['blur', 'change']}
                    ],
                    appointmentAmount: [
                        {required: true, validator: checkAppointmentAmount, trigger: ['blur', 'change']}
                    ],
                    appointmentBegin: [
                        {required: true, validator: checkAppointmentBegin, trigger: ['blur', 'change']}
                    ],
                    depId: [
                        {required: true, message: '请选择科室名称', trigger: 'change'}
                    ],
                    hospitalId: [
                        {required: true, message: '请选择医院名称', trigger: 'change'}
                    ], timeState: [
                        {required: true, message: '请选择上下午时段', trigger: 'change'}
                    ], binId: [
                        {required: true, message: '请选择挂号类型', trigger: 'change'}
                    ], doctorId: [
                        {required: true, message: '请选择医生', trigger: 'change'}
                    ], week: [
                        {required: true, message: '请选择星期', trigger: 'change'}
                    ],
                    startTime: [
                        {required: true, message: '请选择门诊开始时间', trigger: 'change'}
                    ],
                    endTime: [
                        {required: true, message: '请选择门诊结束时间', trigger: 'change'}
                    ], schedulingTime: [
                        {required: true, message: '请选择排班时间', trigger: 'change'}
                    ], tip: [
                        {required: true, message: '请输入个性信息', trigger: 'blur'},
                        {min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur'}
                    ]
                }, weekList: [{
                    name: '全部',
                    id: null
                }, {
                    name: '周一',
                    id: 1
                }, {
                    name: '周二',
                    id: 2
                }, {
                    name: '周三',
                    id: 3
                }, {
                    name: '周四',
                    id: 4
                }, {
                    name: '周五',
                    id: 5
                }, {
                    name: '周六',
                    id: 6
                }, {
                    name: '周日',
                    id: 7
                }], timeList: [{
                    name: '上午',
                    id: 1
                }, {
                    name: '下午',
                    id: 2
                }, {
                    name: '夜门诊',
                    id: 3
                }],
                dialogTableVisible: false,
                dialogFormVisible: false,
                appDialogTableVisible: false,
                formLabelWidth: '120px',
                pickerOptions: {
                    shortcuts: [{

                        text: '本月',
                        onClick(picker) {
                            picker.$emit ('pick', [dayjs ().startOf ('month'), dayjs ().endOf ('month')]);
                        }
                    }, {
                        text: '今年至今',
                        onClick(picker) {
                            const end = new Date ();
                            const start = new Date (new Date ().getFullYear (), 0);
                            picker.$emit ('pick', [start, end]);
                        }
                    }, {
                        text: '最近六个月',
                        onClick(picker) {
                            const end = new Date ();
                            const start = new Date ();
                            start.setMonth (start.getMonth () - 6);
                            picker.$emit ('pick', [start, end]);
                        }
                    }]
                },
                datePickerArray: [dayjs (), dayjs ().add (15, 'day')],
            }
        },
        methods: {
            handleSizeChange(val) {
                console.log (`每页 ${val} 条`);
                this.pageSize = val;
            },
            handleCurrentPageChange(val) {
                console.log (`当前页: ${val}`);
                this.currentPage = val;
                this.lazyLoad ()
            },
            lazyLoad() {
                let startDate = this.datePickerArray[0]
                let endDate = dayjs (this.datePickerArray[1]).add (1, 'day')
                let params = [
                    {name: 'startDate', value: startDate},
                    {name: 'endDate', value: endDate},
                    {name: 'depId', value: this.depId},
                    {name: 'doctorId', value: this.doctorId},
                    {name: 'status', value: this.status},
                    {name: 'week', value: this.week},
                    {name: 'hospitalId', value: this.hospitalId}
                ]
                if (this.status == 2) {
                    params = [
                        {name: 'startDate', value: startDate},
                        {name: 'endDate', value: endDate},
                        {name: 'depId', value: this.depId},
                        {name: 'doctorId', value: this.doctorId},
                        {name: 'status', value: ''},
                        {name: 'week', value: this.week},
                        {name: 'hospitalId', value: this.hospitalId}
                    ]
                }
                axios.post ("http://" + window.location.host + '/ordScheduling/select_list_Page', {
                    "pageNum": this.currentPage,
                    "pageSize": this.pageSize,
                    "params": params
                }).then (res => {
                    this.tableData = res.data.data.content;
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },

            jktSchedulingUploadSingle: function (index, row) {
                let loading = this.$loading ({
                    lock: true,
                    text: '数据处理中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let params = new URLSearchParams ()
                params.append ("id", row.id)
                axios.post ("http://" + window.location.host + '/ordScheduling/jktSchedulingUploadSingle', params).then (res => {
                    console.log (res)
                    if (res.data.code == 200 || res.data.code == '200') {
                        this.init ()
                        this.$message ({
                            showClose: true,
                            type: 'success',
                            message: res.data.msg
                        });
                    } else {
                        this.$alert (res.data.msg.split (";").join ("<br>"), '提示', {
                            confirmButtonText: '确定',
                            callback: action => {

                            }
                        })
                    }
                    loading.close ();
                }).catch ((error) => {
                    loading.close ();
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: error.response.data.message
                    });
                });
            },

            jktSchedulingUpload: function () {
                let loading = this.$loading ({
                    lock: true,
                    text: '数据处理中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let params = new URLSearchParams ()
                if (this.hospitalId == null) {
                    this.hospitalId = 0;
                }
                params.append ("hospitalId", this.hospitalId)
                axios.post ("http://" + window.location.host + '/ordScheduling/jktSchedulingUpload', params).then (res => {
                    console.log (res)
                    if (res.data.code == 200 || res.data.code == '200') {
                        this.init ()
                        this.$message ({
                            showClose: true,
                            type: 'success',
                            message: res.data.msg
                        });
                    } else {
                        this.$alert (res.data.msg.split (";").join ("<br>"), '提示', {
                            confirmButtonText: '确定',
                            callback: action => {

                            }
                        })
                    }
                    loading.close ();
                }).catch ((error) => {
                    loading.close ();
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: error.response.data.message
                    });
                });
            },

            chinese: function () {
                this.doctorName = this.doctorName.replace (/[^\u4E00-\u9FA5]/g, '');
            },
            checkboxT(row, rowIndex) {
                if (row.status == 1 || row.status == '1') {
                    return false;//禁用
                } else {
                    return true;//不禁用
                }
            },
            checkboxTB(row, rowIndex) {
                if (this.status == 0 || this.status == '0') {
                    return true;//禁用
                } else {
                    return false;//不禁用
                }
            },
            init: function () {
                let user = localStorage.getItem ("user");
                if (user.sffCardType == '0') {
                    this.type = false
                }
                let that = this
                that.loading = false
                let startDate = this.datePickerArray[0]
                let endDate = dayjs (this.datePickerArray[1]).add (1, 'day')

                let params = [
                    {name: 'startDate', value: startDate},
                    {name: 'endDate', value: endDate},
                    {name: 'depId', value: this.depId},
                    {name: 'doctorId', value: this.doctorId},
                    {name: 'status', value: this.status},
                    {name: 'week', value: this.week},
                    {name: 'hospitalId', value: this.hospitalId},
                    {name: 'doctorName', value: this.docName}
                ]
                if (this.status == 2) {
                    params = [
                        {name: 'startDate', value: startDate},
                        {name: 'endDate', value: endDate},
                        {name: 'depId', value: this.depId},
                        {name: 'doctorId', value: this.doctorId},
                        {name: 'status', value: ''},
                        {name: 'week', value: this.week},
                        {name: 'hospitalId', value: this.hospitalId},
                        {name: 'doctorName', value: this.docName}
                    ]
                }

                axios.post ("http://" + window.location.host + '/ordScheduling/select_list_Page', {
                    "pageNum": this.currentPage,
                    "pageSize": this.pageSize,
                    "params": params
                }).then (res => {
                    this.tableData = res.data.data.content;
                    this.totalPage = res.data.data.totalPage
                    this.total = res.data.data.totalSize
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });


            },
            docnameselect: function () {
                let user = localStorage.getItem ("user");
                if (user.sffCardType == '0') {
                    this.type = false
                }
                let that = this
                that.loading = false
                let startDate = this.datePickerArray[0]
                let endDate = dayjs (this.datePickerArray[1]).add (1, 'day')

                let params = [
                    {name: 'startDate', value: startDate},
                    {name: 'endDate', value: endDate},
                    {name: 'depId', value: this.depId},
                    {name: 'doctorId', value: this.doctorId},
                    {name: 'status', value: this.status},
                    {name: 'week', value: this.week},
                    {name: 'hospitalId', value: this.hospitalId},
                    {name: 'doctorName', value: this.docName}
                ]
                if (this.status == 2) {
                    params = [
                        {name: 'startDate', value: startDate},
                        {name: 'endDate', value: endDate},
                        {name: 'depId', value: this.depId},
                        {name: 'doctorId', value: this.doctorId},
                        {name: 'status', value: ''},
                        {name: 'week', value: this.week},
                        {name: 'hospitalId', value: this.hospitalId},
                        {name: 'doctorName', value: this.docname}
                    ]
                }
                axios.post ("http://" + window.location.host + '/ordScheduling/select_list_Page', {
                    "pageNum": this.currentPage,
                    "pageSize": this.pageSize,
                    "params": params
                }).then (res => {
                    this.tableData = res.data.data.content;
                    this.totalPage = res.data.data.totalPage
                    this.total = res.data.data.totalSize
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },
            otherInit: function () {
                axios.post ("http://" + window.location.host + '/hospital/select_list', {
                    hosName: '',
                    hospitalId: this.hospitalId
                }).then (res => {
                    this.hospitals = res.data.data;
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });

                axios.post ("http://" + window.location.host + '/pubBindInfo/select_list', {}).then (res => {
                    this.bindInfos = res.data.data;
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
                if (this.hospitalId) {
                    axios.post ("http://" + window.location.host + '/pubDepartments/select_list', {
                        depName: '', depClinic: '1', status: 0, hospitalId: this.hospitalId
                    }).then (res => {
                        this.departments = res.data.data;
                    }).catch ((e) => {
                        this.$message ({
                            showClose: true,
                            type: 'error',
                            message: "获取数据失败"
                        });
                    });
                }

                // axios.post("http://" + window.location.host + '/pubDoctor/select_list', {
                //     doctorName: "", status: 0,
                //     hospitalId: this.hospitalId
                // }).then(res => {
                //     this.doctors = res.data.data;
                // }).catch((e) => {
                //     this.$message({
                //         showClose: true,
                //         type: 'error',
                //         message: "获取数据失败"
                //     });
                // });
            },
            schedulingCache: function () {

                axios.post ("http://" + window.location.host + '/ordScheduling/schedulingCache', {}).then (res => {
                    this.$message ({
                        message: '操作成功！',
                        type: 'success'
                    });
                }).catch ((e) => {
                    this.$message ({
                        showClose: true,
                        type: 'error',
                        message: "获取数据失败"
                    });
                });
            },
            formatterWeek: function (row, column) {
                let week = ""
                switch (row.week) {
                    case 1:
                        week = "星期一";
                        break;
                    case 2:
                        week = "星期二";
                        break;
                    case 3:
                        week = "星期三";
                        break;
                    case 4:
                        week = "星期四";
                        break;
                    case 5:
                        week = "星期五";
                        break;
                    case 6:
                        week = "星期六";
                        break;
                    case 7:
                        week = "星期日";
                        break;
                    default:
                        week = "未知";
                }
                return week;
            },
            formatterHospital: function (row, column) {
                for (let i = 0; i < this.hospitals.length; i++) {
                    if (row.hospitalId == this.hospitals[i].id) {
                        return this.hospitals[i].hosName
                    }
                }
            },
            formatterState: function (row, column) {
                let timeState = ""
                switch (row.state + '') {
                    case '1':
                        timeState = "窗口挂号";
                        break;
                    case '2':
                        timeState = "平台预约取号";
                        break;
                    case '3':
                        timeState = "平台爽约";
                        break;
                    case '4':
                        timeState = "院内预约取号";
                        break;
                    case '5':
                        timeState = "院内爽约";
                        break;
                    case '6':
                        timeState = "退号";
                        break;
                    default:
                        timeState = "未使用";
                }
                return timeState;
            },
            formatterStatus: function (row, column) {
                let timeState = ""
                switch (row.status + '') {
                    case '0':
                        timeState = "未消耗";
                        break;
                    case '1':
                        timeState = "已消耗";
                        break;
                    default:
                        timeState = "未消耗";
                }
                return timeState;
            },
            formatterType: function (row, column) {
                let timeState = ""
                switch (row.type + '') {
                    case '0':
                        timeState = "院内号源";
                        break;
                    case '1':
                        timeState = "第三方号源";
                        break;
                    default:
                        timeState = "未知";
                }
                return timeState;
            },
            formatterTimeState: function (row, column) {
                let timeState = ""
                switch (row.timeState) {
                    case 1:
                        timeState = "上午";
                        break;
                    case 2:
                        timeState = "下午";
                        break;
                    case 3:
                        timeState = "夜门诊";
                        break;
                    default:
                        timeState = "未知";
                }
                return timeState;
            },
            formatterDoctorPracticeScope: function (row, column) {
                let timeState = ""
                switch (row.doctorPracticeScope) {
                    case '0':
                        timeState = "所有渠道";
                        break;
                    case '1':
                        timeState = "自有H5+VIP";
                        break;
                    case '2':
                        timeState = "仅VIP";
                        break;
                    default:
                        timeState = "所有渠道";
                }
                return timeState;
            },
            closeDiglog: function () {
                this.ruleForm = {
                    amount: 80,
                    amountAdd: null,
                    amountCancel: null,
                    amountCurrent: null,
                    amountReduce: null,
                    amountSurplus: null,
                    amountUse: null,
                    appointmentAmount: null,
                    appointmentBegin: null,
                    averageVisitTime: 3,
                    binId: null,
                    binName: null,
                    clinicAddress: null,
                    depId: null,
                    depName: null,
                    doctorId: null,
                    doctorName: null,
                    endTime: null,
                    hospitalId: null,
                    id: null,
                    increase: 0,
                    schedulingTime: null,
                    startTime: null,
                    state: null,
                    status: null,
                    stopServiceReason: null,
                    templateId: null,
                    timeStamp: null,
                    timeState: null,
                    week: null,
                    registrationFee: "0"
                }
            },
            handleCurrentChange(val) {
                this.currentUpRow = val;
            },
            ordSchedulingHandleSelectionChange(selection, row) {
                this.schedulingList = []
                selection.forEach (item => {
                    this.schedulingList.push (item)
                });
            },
            selectOrdSchedulingAll(selection) {
                this.schedulingList = []
                selection.forEach (item => {
                    this.schedulingList.push (item)
                });
            },
            sourceHandleSelectionChange(selection, row) {
                if (row.type == 1) {
                    row.type = 0
                } else {
                    row.type = 1
                }
                axios.post ("http://" + window.location.host + '/ordSourceDetail/update_by_primary_key_selective', row).then (res => {
                    this.$message ({
                        type: 'success',
                        message: '设置成功!'
                    });
                }).catch (function (error) {
                    alert (error.response.data.message)
                });
                // this.appDialogTableVisible = true
                // this.$refs.multipleTable.
            },
            selectAll(selection) {
                if (!this.checkAll) {
                    selection.forEach (row => {
                        if (row.status == "0") {
                            row.type = 1
                            axios.post ("http://" + window.location.host + '/ordSourceDetail/update_by_primary_key_selective', row).then (res => {
                            }).catch (function (error) {
                                alert (error.response.data.message)
                            });
                        }
                    });
                    this.$message ({
                        type: 'success',
                        message: '设置成功!'
                    });
                    this.checkAll = true
                } else {
                    this.ordSourceDetailList.forEach (row => {
                        if (row.status == "0") {
                            row.type = 0
                            axios.post ("http://" + window.location.host + '/ordSourceDetail/update_by_primary_key_selective', row).then (res => {
                            }).catch (function (error) {
                                alert (error.response.data.message)
                            });
                        }
                    });
                    this.$message ({
                        type: 'success',
                        message: '设置成功!'
                    });
                    this.checkAll = false
                }
                // this.appDialogTableVisible = true
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach (row => {
                        this.$refs.multipleTable.toggleRowSelection (row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection ();
                }
            },
            submitForm: function (ruleForm) {
                const loading = this.$loading ({
                    lock: true,
                    text: '正在向号源池增加号源 请稍后',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0   , 0.7)'
                });
                this.$refs[ruleForm].validate ((valid) => {
                    if (valid) {
                        console.log (this.ruleForm);
                        axios.post ("http://" + window.location.host + '/ordScheduling/update_by_primary_key_selective', this.ruleForm).then (res => {
                            this.$message ({
                                type: 'success',
                                message: '创建成功!'
                            });
                            this.lazyLoad ();
                            this.closeDiglog ()
                            loading.close ()
                            this.dialogFormVisible = false
                        }).catch (function (error) {
                            alert (error.response.data.message)
                            loading.close ()
                        });
                    } else {
                        this.$message ({
                            type: 'warning',
                            message: '表单验证不通过，不能保存!'
                        });
                        this.closeDiglog ()
                        this.lazyLoad ();
                        loading.close ()

                        return false;
                    }
                });
            },
            stopList: async function () {
                if (this.schedulingList.length > 0) {
                    // let res.data.msg.split(";").join("<br>")
                    let msg = "";
                    for (let item in this.schedulingList) {
                        msg = msg + this.schedulingList[item].depName
                        msg = msg + this.schedulingList[item].doctorName + "医生"
                        msg = msg + this.schedulingList[item].schedulingTime + "号"
                        msg = msg + (this.schedulingList[item].timeState == 1 ? "上午" : this.schedulingList[item].timeState == 2 ? "下午" : "夜门诊")

                        msg = msg + ";"
                    }
                    await this.$prompt (msg.split (";").join ("<br>"), '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
                        dangerouslyUseHTMLString: true,
                        inputErrorMessage: "请输入取消停诊原因"
                    }).then (async ({value}) => {
                        let loading = this.$loading ({
                            lock: true,
                            text: '数据处理中',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });
                        let index;
                        for (index in this.schedulingList) {
                            console.log ("arr[" + index + "] = " + this.schedulingList[index]);
                            let params = new URLSearchParams ()
                            params.append ("id", this.schedulingList[index].id)
                            params.append ("reason", value);
                            console.log (params)
                            await axios.post ("http://" + window.location.host + '/ordScheduling/doctorStopWork',
                                params
                            ).then (res => {
                            }).catch ((error) => {
                                loading.close ()
                                this.$message ({
                                    type: 'error',
                                    message: error.response.data.data.message
                                });
                            });
                        }
                        console.log ("dd")
                        await axios.post ("http://" + window.location.host + '/ordScheduling/doctorStopWorkCache', {}).then (res => {
                            this.init ();
                            loading.close ()
                        }).catch ((error) => {
                            this.init ();
                            loading.close ()
                            this.$message ({
                                type: 'error',
                                message: error.response.data.data.message
                            });
                        });
                    }).catch (() => {
                        this.init ();
                        loading.close ()
                        this.$message ({
                            type: 'info',
                            message: '你已取消批量停诊！'
                        });
                    });
                } else {
                    this.$message ({
                        type: 'warning',
                        message: "请选择需要停诊的临时排班"
                    });
                }
            },
            deleteRow: async function (index, row) {
                if (row.status == "0") {
                    await this.isAppointment (row)
                } else {
                    await this.stopAppointment (row, "请输入取消停诊原因", "请输入取消停诊原因")
                }
            },
            isAppointment: async function (row) {
                let params = new URLSearchParams ()
                params.append ("id", row.id)
                let message = "请输入停诊原因"
                let msg = "";
                msg = msg + row.depName
                msg = msg + row.doctorName
                msg = msg + row.schedulingTime + "号"
                msg = msg + (row.timeState == 1 ? "上午" : row.timeState == 2 ? "下午" : "夜门诊")
                msg = msg + ";"
                axios.post ("http://" + window.location.host + '/ordSourceDetail/select_list', {"schedulingId": row.id}).then (res => {
                    if (res.data.length > 0) {
                        message = "该排班下已有" + res.data.data.length + "条预约记录，请输入停诊原因";
                    }
                    this.stopAppointment (row, msg, "停诊原因不能为空")
                });
            },
            stopAppointment: async function (row, message, info) {
                let loading = this.$loading ({
                    lock: true,
                    text: '数据处理中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                let params = new URLSearchParams ()
                params.append ("id", row.id)
                this.$prompt (message, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
                    inputErrorMessage: info
                }).then (({value}) => {
                    params.append ("reason", value);
                    axios.post ("http://" + window.location.host + '/ordScheduling/doctorStopWork',
                        params
                    ).then (res => {
                        this.init ();
                        loading.close ()
                        this.$message ({
                            type: 'success',
                            message: '成功!'
                        });
                        this.tableData.splice (index, 1);
                    }).catch ((error) => {
                        loading.close ()
                        this.$message ({
                            type: 'error',
                            message: error.response.data.data.message
                        });
                    });
                }).catch (() => {
                    loading.close ()
                    this.$message ({
                        type: 'info',
                        message: '排班状态变更取消！'
                    });
                });
            },
            editRow: function (index, row) {
                axios.post ("http://" + window.location.host + '/ordSourceDetail/select_list', {
                    "schedulingId": row.id,
                    hospitalId: this.hospitalId
                }).then (res => {
                    if (res.data.data.length > 0) {
                        let count = 0
                        this.ordSourceDetailList = res.data.data;
                        this.ordSourceDetailList.forEach (row => {
                            if (row.type == 1 || row.type == '1') {
                                count = count + 1
                                this.$nextTick (function () {
                                    this.$refs.multipleTable.toggleRowSelection (row);
                                })
                            }
                        });
                        if (count == this.ordSourceDetailList.length) {
                            this.checkAll = true
                        }
                    }
                });
                this.ruleForm = row;
                this.currentAmount = row.amount
                this.dialogFormVisible = true
            },
            detailRow: function (index, row) {
                let params = new URLSearchParams ()
                params.append ("id", row.id)
                axios.post ("http://" + window.location.host + '/ordScheduling/delete_by_primary_key',
                    params
                ).then (res => {
                    this.$message ({
                        type: 'success',
                        message: "删除成功"
                    });
                    this.tableData.splice (index, 1);
                })
            },
            tableRowClassName({row, rowIndex}) {
                if (row.status == 1 || row.status == 2) {
                    return 'error-row';
                } else if (row.type == 1 || row.type == '1') {
                    return 'warning-row';
                } else if (row.status == 0 || row.status == '0') {
                    return '';
                }
                return '';
            },
            cellClass(row) {
                if (row.columnIndex === 0 && this.status != 0) {
                    return 'DisableSelection'
                }
            },
        },
        created() {
            if (this.hospitalId != null) {
                this.isHidden = true
            }
            this.otherInit ()
            this.init ()

        },
        watch: {
            status: function (val, oldval) {
                if (val != oldval) {
                    this.init ()
                }
                if (val == "0") {
                    this.isDisabled = false;
                } else {
                    this.isDisabled = true;
                }
            },
            week: function (val, oldval) {
                if (val != oldval) {
                    this.init ()
                }
            },
            pageSize: function (newValue, oldValue) {
                this.lazyLoad ()
            },
            'hospitalId': function (val, oldval) {
                if (val != oldval) {
                    if (val != null && val != undefined) {
                        this.depId = null
                        this.isDisabled = true;
                        axios.post ("http://" + window.location.host + '/pubDepartments/select_list', {
                            depClinic: '1',
                            hospitalId: this.hospitalId
                        }).then (res => {
                            this.departments = res.data.data;
                            this.doctors = null;
                        }).catch ((e) => {
                            this.$message ({
                                type: 'error',
                                message: "获取数据失败"
                            });
                        });
                        this.init ();
                    }
                }
            },
            'depId': function (val, oldval) {
                if (this.hospitalId == null || this.hospitalId == undefined) {
                    this.depId = null
                    this.$message ({
                        type: 'error',
                        message: "请选择所属馆区"
                    });
                }
                if (val != oldval) {
                    if (val != null && val != undefined) {
                        axios.post ("http://" + window.location.host + '/pubDoctor/select_list', {
                            depId: val,
                            status: '0'
                        }).then (res => {
                            this.doctors = res.data.data;
                        }).catch ((e) => {
                            this.$message ({
                                type: 'error',
                                message: "获取数据失败"
                            });
                        });
                    }
                    this.doctorId = null;
                    this.isDisabled = true;
                    this.init ();
                }
            },
            'doctorId': function (val, oldval) {
                if (this.depId == null || this.depId == undefined) {
                    this.doctorId = null;
                }
                if (val != oldval) {
                    if ((val != null && val != undefined) && this.status == "0") {
                        this.isDisabled = false;
                    }
                    this.init ()
                }
            },
        },
        mounted: function () {
            this.$nextTick (function () {
                this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 80;
                // 监听窗口大小变化
                let self = this;
                window.onresize = function () {
                    self.tableHeight = window.innerHeight - self.$refs.table.$el.offsetTop - 80
                }
            })
        }
    });
</script>

</html>
